<template>
	<view>
		<utop :istype="1"></utop>
		<view class="" v-if="ishide">
			<view class="kongs" v-if="isshow">
				<view class="">
					<image src="../../static/kongs.png" mode=""></image>
					<view class="tss">
						<span v-if="orderinfo.status < 4">吸塑</span>
						<span v-else-if="orderinfo.status <= 4 || orderinfo.status < 6">圆磨</span>
						<span v-else-if="orderinfo.status <= 6">洗片</span>
						工作未结束，暂不可操作
					</view>
				</view>
			</view>
			<view class="" v-else>
				<view class="content">
					<view class="flex_bet items">
						<view class="textLeft">规格型号</view>
						<view class="rightbt">
							{{orderinfo.xinghao_name?orderinfo.xinghao_name:""}}
							{{orderinfo.color_name?orderinfo.color_name:''}}
						</view>
					</view>
					<view class="flex_bet items">
						<view class="textLeft">派单包数</view>
						<view class="">{{orderinfo.bao_num}}</view>
					</view>
					<view class="itemss">
						<view class="flex_bet">
							<view class="" style="width: 260rpx;">
								<view class="textLeft">化镀质量</view>
								<view class="rightinputre" @click="show=!show">
									<view class="s1" v-if="select">{{select}}</view>
									<view class="s2" v-else>请选择质量</view>
									<uni-icons :type="show?'up':'down'" color="#196AEB"></uni-icons>
								</view>
								<view class="rightinputade" v-if="show">
									<view :class="select == item.huadu_level?'itact':'it'" v-for="(item,index) in list"
										:key="index" @click="selectQ(item)">
										{{item.huadu_level}}
									</view>
								</view>
							</view>
							<view class="" style="width: 260rpx;">
								<view class="textLeft">成品密度</view>
								<view class="rightinput">
									<input placeholder-class="ustyle" v-model="params.chengpin_density" type="digit"
										placeholder="请输入" />
								</view>
							</view>
						</view>
						<view class="flex_bet"
							style="border-top: 1px solid #D1D1D6;margin-top: 26rpx;padding-top: 20rpx;">
							<view class="" style="width: 260rpx;">
								<view class="textLeft">成品重量</view>
								<view class="rightinput">
									<input placeholder-class="ustyle" v-model="params.chengpin_weight" type="digit"
										placeholder="请输入" />
									<span>kg</span>
								</view>
							</view>
							<view class="" style="width: 260rpx;">
								<view class="textLeft">成品包数</view>
								<view class="rightinput">
									<input placeholder-class="ustyle" v-model="params.num" type="digit"
										placeholder="请输入" />
									<span>包</span>
								</view>
							</view>
						</view>
					</view>
					<view class="textarea">
						<textarea placeholder="请输入备注" v-model="params.chengpin_remark"></textarea>
					</view>
					<view class="bt">
						<view class="btns" @click="handleAll">
							全部报工
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="popups" type="center">
			<view class="popup1">
				<!-- 第一次报工 -->
				<view class="">
					<uni-icons @click="close(2)" color="#979797" size="24" class="icon" type="closeempty"></uni-icons>
					<view class="img">
						<image src="../../static/info.png" mode=""></image>
					</view>
					<view class="texts">
						<view class="">
							此次报工数量：<span style="color: #196AEB;">{{params.num}}</span>包
						</view>
					</view>
					<view class="beizhu">
						<view class="" style="display: flex;">
							<view class="" style="width: 90rpx;">
								备注：
							</view>
							<view class="" style="flex: 1;">
								{{params.chengpin_remark?params.chengpin_remark:'无'}}
							</view>
						</view>
					</view>
					<view class="context">
						是否确认<span style="color: #196AEB;">全部报工</span>已完成？
					</view>
					<view class="bnts">
						<view class="btn b1" @click="close(2)">
							取消
						</view>
						<view class="btn b2" @click="handleTj">
							确认提交
						</view>
					</view>
				</view>
				<!-- 多次报工 -->
			</view>
		</uni-popup>
		<uni-popup ref="popupYes" type="center" :is-mask-click="false">
			<view class="yes">
				<view class="img">
					<image src="../../static/yes.png" mode=""></image>
				</view>
				<view class="ts">
					您已提交此订单全部完成，不支持再操作
				</view>
				<view class="" style="display: flex;align-items: center;">
					<view class="btn" @click="goi">
						首页
					</view>
					<view class="btn" @click="goindex">
						扫描新订单
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getOrderInfo,
		setxiazuanWork
	} from '@/common/http.api.js'
	export default {
		data() {
			return {
				isshow: true,
				show: false,
				ishide: false,
				select: '',
				list: [{
						id: 2,
						huadu_level: '优'
					},
					{
						id: 3,
						huadu_level: '良'
					},
					{
						id: 4,
						huadu_level: '差'
					}
				], //1=无,2=优,3=良,4=差

				orderinfo: {},
				params: {
					order_id: 0,
					num: '',
					huadu_level: '',
					chengpin_density: '',
					chengpin_weight: '',
					chengpin_remark: ''
				},
				userInfo: uni.getStorageSync('userinfo')
			};
		},
		onLoad(option) {
			this.params.order_id = option.id
			this.getOrderInfoFun()
		},
		methods: {
			getOrderInfoFun() {
				getOrderInfo({
					order_id: this.params.order_id
				}).then(res => {
					this.orderinfo = res.data
					if (res.data.status == 7) {
						this.ishide = true
						this.isshow = false //正常
					} else if (res.data.status >= 8) {
						this.ishide = false
						this.$refs.popupYes.open()
					} else {
						this.ishide = true
						this.isshow = true
					}
				})
			},
			selectQ(item) {
				this.select = item.huadu_level
				this.params.huadu_level = item.id
				this.show = false
			},
			goi(){
				uni.redirectTo({
					url:'/pages/index/index'
				})
			},
			goindex() {
				let that = this
				uni.scanCode({
					barCodeInput: true,
					onlyFromCamera: true,
					success: function(res) {
						if (res.errMsg == "scanCode:ok") {
							let id = res.path.substring(res.path.lastIndexOf('?') + 1, res.path.length)
								.substring(9)
							setTimeout(() => {
								that.handleSm(id)
								that.$refs.popupYes.close()
							}, 500)
						}
					},
				})
			},
			handleSm(id) {
				if (this.userInfo.type == 1) {
					uni.redirectTo({
						url: `/pages/index/xspage?id=${id}`
					})
				}
				if (this.userInfo.type == 2) {
					uni.redirectTo({
						url: `/pages/index/ympage?id=${id}`
					})
				}
				if (this.userInfo.type == 3) {
					uni.redirectTo({
						url: `/pages/index/xppage?id=${id}`
					})
				}
				if (this.userInfo.type == 4) {
					uni.redirectTo({
						url: `/pages/index/xzpage?id=${id}`
					})
				}

			},
			close(type) {
				if (type == 1) {
					this.$refs.popup.close()
				} else {
					this.$refs.popups.close()
				}
			},
			handleAll() {
				if (this.params.num == '' ||
					this.params.huadu_level == '' ||
					this.params.chengpin_weight == '' ||
					this.params.chengpin_weight == '') {
					uni.showToast({
						icon: 'none',
						title: "请完整填写数据"
					})
					return
				}
				this.$refs.popups.open()
			},
			//点击提交按钮
			handleTj() {
				
				setxiazuanWork(this.params).then(res => {
					if (res.code == 1) {
						this.ishide = false
						this.$refs.popups.close()
						this.$refs.popupYes.open()
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F8FA;
	}

	.ustyle {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #979797;
	}

	.kongs {
		background-color: #fff;
		width: 100%;
		display: flex;
		justify-content: center;
		height: 100vh;

		image {
			margin: 240rpx auto 100rpx;
			width: 400rpx;
			height: 324rpx;
		}

		.tss {
			font-family: PingFang SC, PingFang SC;
			font-size: 32rpx;
			color: #979797;

			span {
				font-weight: bold;
				color: #196AEB;
			}
		}
	}

	.content {
		background-color: #F7F8FA;
		padding: 20rpx;
		box-sizing: border-box;

		.bt {
			width: 710rpx;
			position: absolute;
			bottom: 40rpx;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			box-sizing: border-box;

			.btns {
				width: 670rpx;
				height: 90rpx;
				background: #196AEB;
				border-radius: 50rpx;
				text-align: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 90rpx;
				margin: 0 auto;
			}
		}
	}


	.items {
		width: 710rpx;
		height: 120rpx;
		background: #FFFFFF;
		border-radius: 22rpx;
		padding: 34rpx 30rpx 34rpx 44rpx;
		box-sizing: border-box;
		margin: 0rpx auto 20rpx;

		.rightbt {
			height: 60rpx;
			background: #F2F8FF;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			border: 1rpx solid #196AEB;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #196AEB;
			line-height: 60rpx;
			text-align: center;
			padding: 0rpx 10rpx;
		}
	}

	.itemss {
		background: #FFFFFF;
		border-radius: 22rpx;
		padding: 28rpx 44rpx;

		.textLeft {
			margin-bottom: 24rpx;
			width: 200rpx;
			text-align: center;
		}

		.rightinputre {
			width: 200rpx;
			border: 1px solid #196AEB;
			height: 56rpx;
			border-radius: 8rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 10rpx 14rpx;
			box-sizing: border-box;
			position: relative;
			text-align: center;

			.s1 {
				width: 200rpx;
				font-family: DIN, DIN;
				font-weight: bold;
				font-size: 40rpx;
				color: #196AEB;
				text-align: center;
			}

			.s2 {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #979797;
			}
		}

		.rightinputade {
			position: absolute;
			width: 198rpx;
			border: 1px solid #196AEB;
			background-color: #fff;
			text-align: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;
			border-top: none;
			border-radius: 0rpx 0rpx 8rpx 8rpx;
			z-index: 9;

			.it {
				line-height: 60rpx;
			}

			.itact {
				background-color: #196AEB;
				color: #fff;
				line-height: 60rpx;
			}
		}

		.rightinput {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			display: flex;
			align-items: center;
			text-align: center;

			input {
				width: 200rpx;
				font-family: DIN, DIN;
				font-weight: bold;
				font-size: 40rpx;
				color: #196AEB;
				border: 1px solid #D1D1D6;
				height: 56rpx;
				border-radius: 8rpx;
				padding-left: 8rpx;
			}

			span {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #979797;
				margin-left: 6rpx;
			}
		}

	}

	.textarea {
		width: 710rpx;
		height: 280rpx;
		background: #FFFFFF;
		border-radius: 22rpx 22rpx 22rpx 22rpx;
		margin-top: 20rpx;
		padding: 24rpx;
		box-sizing: border-box;

		textarea {
			width: 100%;
		}
	}

	.popup1 {
		background-color: #FFFFFF;
		width: 600rpx;
		border-radius: 30rpx;
		padding: 56rpx 30rpx;
		box-sizing: border-box;
		text-align: center;

		.icon {
			top: 28rpx;
			right: 40rpx;
			position: absolute;
		}

		.img {
			width: 152rpx;
			height: 152rpx;
			margin: 0rpx auto;

			image {
				width: 152rpx;
				height: 152rpx;
			}
		}

		.texts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #666666;
			margin: 34rpx auto 0rpx;

			span {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
			}
		}

		.context {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
			line-height: 35rpx;
		}

		.beizhu {
			text-align: left;
			margin: 24rpx auto;
			width: 540rpx;
			background: #F3F3F3;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			padding: 10rpx 18rpx;
			box-sizing: border-box;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #666666;
			display: flex;
			justify-content: center;
		}

		.bnts {
			display: flex;
			margin-top: 36rpx;
			justify-content: space-between;

			.btn {
				width: 250rpx;
				height: 80rpx;
				background: #FFFFFF;
				border-radius: 40rpx;
				line-height: 80rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
			}

			.b1 {
				border: 1rpx solid #979797;
				color: #979797;
			}

			.b2 {
				background: #196AEB;
				color: #FFFFFF;
			}
		}
	}

	.yes {
		background-color: #FFFFFF;
		width: 600rpx;
		border-radius: 30rpx;
		padding: 56rpx 30rpx;
		box-sizing: border-box;
		text-align: center;

		.img {
			width: 152rpx;
			height: 152rpx;
			margin: 0rpx auto;

			image {
				width: 152rpx;
				height: 152rpx;
			}
		}

		.ts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #333333;
			margin-top: 20rpx;
		}

		.btn {
			height: 80rpx;
			background: #196AEB;
			border-radius: 40rpx;
			margin: 60rpx auto 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #FFFFFF;
			line-height: 80rpx;
			text-align: center;
			padding: 0rpx 60rpx;
		}
	}
</style>